package mgslangpack;
import java.awt.*;
import java.awt.event.*;
import java.sql.*;
import javax.swing.*;
public class UpdateStaff
{
    public UpdateStaff() throws Exception
    {
        final TextField tf1,tf2,tf3,tf4,tf5,tf6,tf7,tf8,tf9,tf10,tf11;
        Label l1,l2,l3,l4,l5,l6,l7,l8,l9,l10,l11,l12;
        Button b1,b2,b3;
        final JFrame f;
        f= new JFrame("Update Staff Info");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(800,800);
        f.setLayout(null);
        f.setVisible(false);
        Container ctn=f.getContentPane();
        ctn.setBackground(Color.LIGHT_GRAY);
        JLabel Pic;
        Pic=new JLabel(new ImageIcon("bouquet.jpg"));
        Pic.setBounds(1,1,800,800);
        ctn.add(Pic);
        Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        final Connection con =
        DriverManager.getConnection("jdbc:odbc:TheOZ_DB","","");
        Font f1 = new Font("Times New roman",Font.BOLD,24);
        l1 = new Label("Update Staff Member's Details:");
        l1.setBounds(50,10,500,40);
        l1.setFont(f1);
        f.add(l1);
        l2= new Label("Discription:");
        l2.setBounds(50,100,100,30);
        f.add(l2);
        tf1 = new TextField(); tf1.setBounds( 200,100,150,25); f.add(tf1);
        l3= new Label("ID Number:");
        l3.setBounds(400,100,100,30);
        f.add(l3);
        tf2 = new TextField(); tf2.setBounds( 500,100,250,25); f.add(tf2);
        l4= new Label("Name:");
        l4.setBounds(50,200,100,30);
        f.add(l4);
        tf3 = new TextField(); tf3.setBounds( 200,200,150,25); f.add(tf3);
        l5= new Label("Surname:");
        l5.setBounds(400,200,100,30);
        f.add(l5);
        tf4 = new TextField(); tf4.setBounds( 500,200,150,25); f.add(tf4);
        l6= new Label("Phone No. (H/W):");
        l6.setBounds(50,250,100,30);
        f.add(l6);
        tf5 = new TextField(); tf5.setBounds( 200,250,150,25); f.add(tf5);
        l7= new Label("Cell Number:");
        l7.setBounds(400,250,100,30);
        f.add(l7);
        tf6 = new TextField(); tf6.setBounds( 500,250,150,25); f.add(tf6);
        l8= new Label("E-mail Address:");
        l8.setBounds(50,300,150,30);
        f.add(l8);
        tf7=new TextField(); tf7.setBounds( 200,300,230,25); f.add(tf7);
        l9=new Label("Address:");
        l9.setBounds(50,350,100,30);
        f.add(l9);
        tf8=new TextField(); tf8.setBounds( 200,350,200,25); f.add(tf8);
        l10= new Label("Suburb:");
        l10.setBounds(50,400,100,30);
        f.add(l10);
        tf9=new TextField(); tf9.setBounds( 200,400,185,25); f.add(tf9);
        l11= new Label("Town:");
        l11.setBounds(50,450,100,30);
        f.add(l11);
        tf10 = new TextField(); tf10.setBounds( 200,450,150,25); f.add(tf10);

        l12= new Label("Code:");
        l12.setBounds(50,500,100,30);
        f.add(l12);
        tf11 = new TextField(); tf11.setBounds( 200,500,100,25); f.add(tf11);
        b1 = new Button("Update");
        b1.setBounds(400,550,80,40);
        b1.addActionListener( new ActionListener()
        {
            public void actionPerformed(ActionEvent e)
            {
                try
                {
                    String s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,s11;
                    s1=tf1.getText();
                    s2=tf2.getText();
                    s3=tf3.getText();
                    s4=tf4.getText();
                    s5=tf5.getText();
                    s6=tf6.getText();
                    s7=tf7.getText();
                    s8=tf8.getText();
                    s9=tf9.getText();
                    s10=tf10.getText();
                    s11=tf11.getText();
                    PreparedStatement ps = con.prepareStatement("UPDATE Staff SET StaffFirstName="+s3+", StaffLastName="+s4+", StaffPhoneNo="+s5+", StaffCellNo="+s6+", StaffEmail="+s7+", StaffPOBox="+s8+", StaffSuburb="+s9+", StaffTown="+s10+", StaffCode="+s11+", StaffDiscription="+s1+" WHERE StaffID="+s2);
                    int i = ps.executeUpdate();
                    JOptionPane.showMessageDialog(null,"Staff Details Updated");
                    tf1.setText("");
                    tf2.setText("");
                    tf3.setText("");
                    tf4.setText("");
                    tf5.setText("");
                    tf6.setText("");
                    tf7.setText("");
                    tf8.setText("");
                    tf9.setText("");
                    tf10.setText("");
                    tf11.setText("");
                }
                catch(Exception e1){JOptionPane.showMessageDialog(null,"Error!\nCould not update record.");}
            }
        }
        );
        f.add(b1);
        b2 = new Button("Back");
        b2.setBounds(80,650,80,30);
        b2.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e2)
            {
                try
                {
                    f.hide();
                    MenuAdmin m = new MenuAdmin();
                }
                catch(Exception e3){}
            }
        } );
        f.add(b2);
        b3 = new Button("Exit");
        b3.setBounds(600,650,80,30);
        b3.addActionListener(new ActionListener()
        {
            public void actionPerformed(ActionEvent e2)
            {
                try
                {
                    System.exit(0);
                }
                catch(Exception e3){}
            }
        });
        f.add(b3);
        f.show();
    }
}
/******************************************************************************/